Little changes on Colombian Programming Contest solutions.
[and.git] / 12318 - Digital Roulette / 12318.2.cpp
blob1e56b0016068ed0c96c5e6898e4c86c7258d6182
1 // Equipo Poncho, Carriel y Ruana
2 // Accepted on UVa
3 using namespace std;
4 #include <algorithm>
5 #include <iostream>
6 #include <iterator>
7 #include <sstream>
8 #include <fstream>
9 #include <cassert>
10 #include <climits>
11 #include <cstdlib>
12 #include <cstring>
13 #include <string>
14 #include <cstdio>
15 #include <vector>
16 #include <cmath>
17 #include <queue>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 template <class T> string toStr(const T &x)
24 { stringstream s; s << x; return s.str(); }
25 template <class T> int toInt(const T &x)
26 { stringstream s; s << x; int r; s >> r; return r; }
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " = " << (x) << endl;
32 const double EPS = 1e-9;
34 int cmp(double x, double y = 0, double tol = EPS) {
35 return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
38 int degree[11];
40 int main(){
41 int n, m;
42 while (scanf("%d %d", &n, &m) == 2) {
43 if (n == 0 and m == 0) break;
44 int k; scanf("%d", &k);
45 for (int i = 0; i < k + 1; ++i) {
46 scanf("%d", &degree[i]);
48 int mod = n + 1;
49 set<int> ans;
50 for (int x = 0; x <= m; x++){
51 int y = 0;
52 int d = 1;
53 for (int i = 0; i < k + 1; ++i) {
54 y += (1LL * degree[i] * d) % mod;
55 if (y >= mod) y -= mod;
57 d = (1LL * d * x) % mod;
59 ans.insert(y);
61 printf("%d\n", (int)ans.size());
63 return 0;